/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aiaudio.processing.base.helpers;

import java.io.IOException;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;

/**
 *
 * @author nastya
 */
public abstract class AccumulationOperation<Res, TableType extends HTable> {

    private TableType table;
    private long version;
    
    private int batchCount = 1;

    public AccumulationOperation(TableType table, long version) {
        this.table = table;
        this.version = version;
    }

    public Res calculate() throws IOException {
        Scan scan = new Scan();
        scan.setTimeStamp(version);
        ResultScanner scanner = table.getScanner(scan);
        Result result = null;
        while ((result = scanner.next()) != null) {
            processRow(result);
        }
        scanner.close();
        return caculateResult();
    }

    protected abstract void processRow(Result result);

    protected abstract Res caculateResult();
}
